WDV221 Intro Javascript

Project-5 Loops Homework 5

 

Instructions:

1. Create a function enterNames( ). Create a button that will call the enterNames( ). The function will start a loop that will ask you for a name until you tell the function that you do not have any more names.  The body of the loop will display each name in the following format:  “You entered:  name”.  It will keep a count of the number of names entered. After you display each name the loop will ask you if you have more names to enter. If you enter ‘yes’ the loop will continue. If you enter 'no' the loop will stop. Once the loop stops you should get a message that says how many names you entered. It should looking something like "You entered ? names. Thank you".

Note: This type of loop is often used when asking the customer or user for input. Most of the time we do not know how many items the customer has to enter. For example: You need to order a number of products and the loop will ask you for the name, quantity and price for each product. It will keep asking you until you do not have any items left to enter. It will then end the loop and complete its processing.

 

2. Create a function called totalSales( ). The function will use a loop to ask the user to enter amounts until they enter the word "done". The body of the loop will add the input amount to a variable called totalSales. When the loop ends the function should display the value of totalSales in an alert.

Note: This is called an accumulator loop. It is often used when gathering information such as prices for each product, quantities of products, continue shopping, etc.


3. Create a runtime script that will use a nested For loop to create a table with 3 rows with 5 cells in each row. Place the same number or a letter in each cell.

Note: Javascript is often used to create HTML elements as part of creating/loading a page. It is commonly used to populate drop down lists, lists and tables.